package fr.ants.controller.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import fr.ants.controller.command.ApplyNestCommand;
import fr.ants.controller.command.ApplySimulationCommand;
import fr.ants.view.HMI;

/**
 * Listener for the buttons apply.
 */
public class ApplyButtonListener implements ActionListener {

	/**
	 * command apply for the button apply in the nest panel.
	 */
	private ApplyNestCommand applyNestCommand;
	/**
	 * command apply for the button apply in the simulation panel.
	 */
	private ApplySimulationCommand applySimulationCommand;

	public ApplyButtonListener() {
		// do nothing
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		// in the panel nest
		if (e.getActionCommand().equals(HMI.APPLY_ACTION_NEST)) {
			if (applyNestCommand != null) {
				applyNestCommand.execute();
			}
		} else
		// in the panel simulation
		if (e.getActionCommand().equals(HMI.APPLY_ACTION_SIMULATION)) {
			if (applySimulationCommand != null) {
				applySimulationCommand.execute();
			}
		}
	}

	/**
	 * set the command for the button apply in the nest panel.
	 * 
	 * @param command
	 *            ApplyNestCommand
	 */
	public void setApplyNestCommand(ApplyNestCommand applyNestCommand) {
		this.applyNestCommand = applyNestCommand;
	}

	/**
	 * set the command for the button apply in the simulation panel.
	 * 
	 * @param command
	 *            ApplySimulationCommand
	 */
	public void setApplySimulationCommand(
			ApplySimulationCommand applySimulationCommand) {
		this.applySimulationCommand = applySimulationCommand;
	}

}
